<template>
	<view class="container">
		<header-bar :config='config'></header-bar>
		<view class="main">
			<view class="detail-task-item">
				<view class="item-header">
					<text class="sn-text">配送单号：{{data.number}}</text>
					<!-- <text class="state-text">{{stateName[state]}}</text> -->
				</view>
				<address-info-card showPickupAddress :data="data" :state="state"></address-info-card>
			</view>
			<view class="item-card">
				<view class="order-info">
					<view>
						<view class="title">商品数量</view>
						<view><text>{{data.totalAmount}}</text>件</view>
					</view>
					<view>
						<view class="title">总重量</view>
						<view><text>{{data.totalWeight}}</text>kg</view>
					</view>
					<view>
						<view class="title">总体积</view>
						<view><text>{{data.totalVolume}}</text>方</view>
					</view>
				</view>
				<view class="item-card-header bottom-line">
					<text>商品清单</text>
				</view>
				<view class="pro-table">
					<view class="table-header">
						<view class="tr">
							<text class="td pro-name">商品名称</text>
							<text class="td pro-num">数量</text>
							<text class="td pro-weight">重量</text>
						</view>
					</view>
					<view class="table-body">
						<view class="tr" v-for="(item,index) in data.details" :key="index" v-show="index<=4||showMore==true">
							<view class="td pro-name flex-v-c">
							<image class="pro-image" :src="easyGetImgUrl(item.picture)" mode="aspectFill"></image>
							<view>
								<view>{{item.productName}}</view>
								<text style="color:#999">{{item.attribute}}</text class="color-gray-3">
							</view>
							</view>
							<text class="td pro-num">×{{item.amount}}</text>
							<text class="td pro-weight">{{item.weight||0}}kg</text>
						</view>
						<view class="flex-center" v-if="data.details&&data.details.length>5">
							<text class="showmore-btn" :class="showMore==true?'fold-btn':'unfold-btn'" @click="showMore=!showMore">
								{{showMore==true?'收起':'展示全部商品'}}
							</text>
						</view>
					</view>
					<view class="table-footer">
						<view class="tr">
							<text class="td pro-name ">合计：共{{data.severalProduct}}种</text>
							<text class="td pro-num">{{data.totalAmount}}件</text>
							<text class="td pro-weight">{{data.totalWeight||0}}kg</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 弹窗 -->
		<uni-popup ref="centerPopup" :mask-click="true" @maskClick="canclePopup">
			<view class="toast">
				<view class="toast-type">选择联系人</view>
				<view class="toast-msg">
					<view class="toast-tel" @click="makePhoneCall(linkPhone)">
						仓库联系方式：{{linkPhone||"暂无"}}
					</view>
					<view class="toast-tel" @click="makePhoneCall(storeLinkPhone)">
						门店联系方式：{{storeLinkPhone||"暂无"}}
					</view>
				</view>

			</view>
		</uni-popup>
		<view class="bottom-bar">
			<button class="btn"  @click="grab">立即接单</button>
		</view>
	</view>
</template>

<script>
	import addressInfoCard from "@/pages_tms/components/order/address-info-card.vue"
	import detailTaskItem from "@/pages_tms/components/order/detail-task-item.vue"
	import easyLabelValue from "@/components/easy/easy-label-value.vue"
	import storage from "@/uni-sub-base/utils/storage.js"
	import {
		uploadImage
	} from "@/service/api/file.js"
	import {
		OrderDetail,
		OrderHandle,
		OrderDelivery
	} from "@/pages_tms/service/logistics.js"
	import {
		getLocation
	} from "@/uni-sub-base/utils/mapUtil.js"
	export default {
		components: {
			detailTaskItem,
			easyLabelValue,
			addressInfoCard
		},
		data() {
			return {
				config: {
					title: '待接单详情',
					centerSlot: true,

				},
				num: 0,
				imageList: [],
				getImageList: [],
				content: '',
				maxLengthText: '100',
				data: {},
				state: 0,
				// 联系电话
				storeLinkPhone: 0,
				linkPhone: 0,
				showMore:false,
				stateName: ["待分配", "待取货", "待配送", "配送中", "已送达"],
				id:null
			}
		},
		mounted() {

		},
		onLoad(e) {
			console.log(e)
			if (e && e.id && e.id != 'undefined') {
				this.id = e.id;
				this.orderDetail(e.id)
			} else {
				this.easyToast("请检查订单号是否正确")
				setTimeout(() => {
					this.easyGoBack()
				}, 2000)
			}
		},
		onShow() {},
		methods: {
			orderDetail(id) {
				OrderDetail(id).then(res => {
					if (res.State == 1) {
						this.data = res.Data || {}
						this.state = Number(this.data.status) || 0
						this.getImageList=[]
						if(!this.data.payType){
							this.data.payType ="已付款"
						}else if(data.payType==1){
							this.data.payType ="货到付款"
						}
						if(this.data.completeUrl){
							let _list =this.data.completeUrl.split(",")
							console.log(_list)
							_list.forEach(item=>{
								if(item){
									this.getImageList.push(item)
								}
							})
						}
					} else {
						this.easyToast(res.Msg)
					}
				})
			},
			grab(){
				let deliveryId = storage.getCache("deliveryId");
				if(!deliveryId){
					this.easyToast('请先完善车辆信息')
					return
				}
				let param = {
					orderId:this.id,
					deliveryId:deliveryId
				}
				OrderDelivery(param).then(res => {
					if (res.State == 1) {
						this.easyRemoveCurrentGoTo("/pages_tms/packet/order/list?state=1")
					} else {
						this.easyToast(res.Msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.container{
		padding-bottom: 120rpx;
	}
	.main {
		padding: $app-page-padding;
	}

	.item-card {
		background: $color-white;
		border-radius: 8rpx;
		margin-top: 20rpx;
		display: flex;
		flex-direction: column;

		.item-card-header {
			padding: $app-page-padding;

			text {
				font-size: $font-size-28;
				font-weight: bold;
			}
		}

		.item-card-main {
			padding: 10rpx $app-page-padding;
		}

		.item-card-main-reamrk {
			background: #F7F7F7;
			margin: 0 $app-page-padding $app-page-padding;
			border-radius: 8rpx;
			padding: $app-page-padding;
		}
	}

	.bottom-line {
		border-bottom: solid 1rpx $border;
	}

	.reamrk-text {
		font-size: $font-size-28;
	}

	.pro-table {
		.table-header {
			background: #F0F3F8;

			.td {
				color: $app-color-text-desc;
			}
		}

		.table-body {
			.td {
				color: $app-color-text-desc;
			}

			.pro-name {
				color: $app-color-text-main;
				// font-weight: bold;
			}
		}

		.table-footer {
			border-top: solid 1rpx $border;

			.td {
				font-weight: bold;
			}
		}

		.tr {
			display: flex;
			flex-direction: row;
			align-items: center;

			.td {
				display: flex;
				padding: $app-page-padding;
				font-size: $font-size-28;
			}
		}

		.pro-name {
			flex: 6;
			
			.pro-image{
				width: 96rpx;
				height: 96rpx;
				border-radius: 8rpx;
				margin-right: 16rpx;
				flex-shrink: 0;
				flex-grow: 0;
			}
		}

		.pro-num {
			flex: 2;
			justify-content: flex-end;
		}

		.pro-weight {
			flex: 2;

			justify-content: flex-end;
		}
	}

	.type-cell {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		background: #FFFFFF;
		border-radius: 8rpx;
		padding: 34rpx 24rpx 10rpx 24rpx;
		margin-bottom: 0;

		.cell-title {
			display: flex;
			flex: 1;
			font-size: 30rpx;
			color: $color-gray-1;
			margin-bottom: 32rpx;
		}

		.types {
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			justify-content: space-between;

			.btn {
				width: 140rpx;
				padding: 0;
				border-radius: 10rpx;
				font-size: 26rpx;
				height: 52rpx;
				border: 1rpx solid #F6F6F6;
				color: $color-gray-1;
				margin-bottom: 20rpx;
				background: #F6F6F6;
			}

			.btnactive {
				background: #FFFFFF;
				color: #FFAE45;
				border-color: #FFAE45;
			}

			&:after {
				content: ' ';
				width: 48%; //这个宽度和子元素宽度一致
				height: 0;
				display: block;
			}
		}
	}

	.textarea {
		display: flex;
		width: 96%;
		padding: 2%;
		min-height: 140rpx;
		font-size: $font-size-24;
		line-height: 40rpx;
		height: 200rpx;
		background: #F6F7F7;
		border-radius: 8rpx;
		// border: 1rpx solid #ec808d;
	}

	.acton-bar {
		margin-top: 70rpx;

		.btn {
			width: 100%;
			height: 80rpx;
		}

	}

	.number {
		padding-top: 10rpx;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		font-size: 24rpx;

		background: #F6F7F7;
		padding-bottom: 10rpx;
		margin-bottom: 10rpx;

		.pr10 {
			padding-right: 10rpx;
			color: #CCCCCC;
		}

		.strong {
			font-size: 26rpx;
		}

	}

	.img-cell {
		display: flex;
		flex: 1;
		flex-direction: row;
		flex-wrap: wrap;

		&:after {
			content: ' ';
			width: 25%; //这个宽度和子元素宽度一致
			height: 0;
			display: block;
		}

		.img-item {
			position: relative;
			width: 130rpx;
			height: 130rpx;
			margin-bottom: 38rpx;
			margin-right: $app-item-padding;

			.img {
				width: 130rpx;
				height: 130rpx;
				border-radius: $border-radius-10;
			}

			.btn-del {
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;
				top: -36rpx;
				right: -36rpx;
				width: 50rpx;
				height: 50rpx;
				border-radius: 40rpx;
				background: rgba($color-black, 0.3);
				color: $color-white;
				margin: 15rpx;
			}
		}

		.add-img {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			width: 128rpx;
			height: 128rpx;
			border-radius: $border-radius-10;
			border: dashed 1rpx $color-gray-6;
			margin-right: $app-item-padding;
			margin-bottom: $app-item-padding;

			text {
				margin-top: 0rpx;
			}
		}
	}

	.img-type-cell {
		padding-top: 10rpx;
		margin-bottom: 20rpx;
	}

	.order-item {
		height: 60rpx;
		display: flex;

		.label {
			flex-grow: 0;
			width: 140rpx;
			line-height: 60rpx;
			font-size: 28rpx;
			text-align: justify;
			text-align-last: justify;
			color: $color-gray-3;
		}

		.value {
			padding-left: 20rpx;
			line-height: 60rpx;
			font-size: 28rpx;
		}
	}
	.showmore-btn{
		margin: 24rpx 0;
		font-size: 24rpx;
		padding: 8rpx 56rpx 8rpx 24rpx;
		border: 2rpx solid #B9C0D0;
		border-radius: 28rpx;
		position: relative;
		&:after{
			position: absolute;
			content: '';
			width: 12rpx;
			height: 12rpx;
			border: 2rpx solid;
			border-color: currentColor currentColor transparent transparent;
		}
	}
	.fold-btn:after{
		transform: rotate(-45deg);
		right: 24rpx;
		top: 22rpx;
	}
	.unfold-btn:after{
		transform: rotate(135deg);
		right: 24rpx;
		top: 10rpx;
	}
	.detail-task-item {
		padding: $app-page-padding;
		background: $color-white;
		border-radius: 16rpx;
	
		.item-header {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-bottom: $app-page-padding;
	
			.sn-text {
				font-size: $font-size-28;
			}
	
			.state-text {
				font-size: $font-size-28;
				color: $color-tms-orange-1;
			}
		}
	
		.item-desc {
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: $app-page-padding 0;
	
			.desc-box {
				margin-right: 20rpx;
	
				.desc-box-label {
					color: $app-color-text-tip;
				}
			}
	
			.go-detail {
				display: flex;
				flex-direction: row;
				justify-content: flex-end;
	
				text {
					color: #898B9D
				}
			}
		}
	
		.item-footer {
			display: flex;
			flex-direction: row;
	
			.item-btn {
				display: flex;
				flex-direction: column;
				padding-right: 15rpx;
				padding-left: 10rpx;
				margin-right: 20rpx;
	
				.icon-btn-tel {
					color: #0091FF;
					margin-bottom: 10rpx;
				}
	
				.btn-text {
					font-size: $font-size-28;
				}
			}
	
			.action-bar {
				flex: 1;
				background: #252C39;
				border-radius: 8rpx;
			}
		}
	}
	
	.item-actions {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-top: $app-page-padding;
		height: 80rpx;
	
		.actions-item {
			flex: 1;
			border-right: solid 2rpx #E5E9F0;
			margin-right: 20rpx;
	
			&:nth-child(2) {
				border-right: none;
			}
	
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
	
			text {
				font-size: $font-size-28;
				margin: 0 8rpx;
				color: $app-color-main-tms;
			}
		}
	
		.btn {
			min-width: 240rpx;
			height: 80rpx;
			border-radius: 100rpx;
	
			text {
				color: $color-white;
			}
		}
	}
	
	.btn-main-tms {
		background: $app-color-main-tms;
	}
	.order-info{
		padding: $app-page-padding 0;
		display: flex;
		justify-content: space-around;
		margin-top:$app-item-padding;
		padding-bottom: 40rpx;
		border-bottom: 1rpx solid #F0F0F0;
		&>view{
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size:24rpx;
			color: #333;
			.title{
				padding-bottom: 12rpx;
				color: #666;
			}
			text{
				font-size: 34rpx;
				font-weight: bold;
			}
		}
	}
	.bottom-bar{
		display: flex;
		justify-content: flex-end;
		.btn{
			width: 654rpx;
			height: 80rpx;
			background: #0091FF;
			border-radius: 12rpx;
			color:#fff;
			font-size: 34rpx;
		}
	}
</style>
